home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3c / setjmp.z / setjmp
Encoding:
Text File  |  1998-10-20  |  8.1 KB  |  198 lines

  1.  
  2.  
  3.  
  4. SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))                                                          SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      setjmp, longjmp, sigsetjmp, siglongjmp, _setjmp, _longjmp - non-local
  10.      gotos
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<sssseeeettttjjjjmmmmpppp....hhhh>>>>
  14.  
  15.    _S_y_s_V:
  16.      iiiinnnntttt sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
  17.  
  18.      vvvvooooiiiidddd lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
  19.  
  20.    _P_O_S_I_X:
  21.      iiiinnnntttt ssssiiiiggggsssseeeettttjjjjmmmmpppp ((((ssssiiiiggggjjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt ssssaaaavvvveeeemmmmaaaasssskkkk))));;;;
  22.  
  23.      vvvvooooiiiidddd ssssiiiigggglllloooonnnnggggjjjjmmmmpppp ((((ssssiiiiggggjjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
  24.  
  25.    _B_S_D:
  26.      iiiinnnntttt sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
  27.  
  28.      iiiinnnntttt lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
  29.  
  30.      iiiinnnntttt ____sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
  31.  
  32.      iiiinnnntttt ____lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
  33.  
  34.      To use the BSD versions of _s_e_t_j_m_p and _l_o_n_g_j_m_p, you must either
  35.  
  36.      1) #define ____BBBBSSSSDDDD____SSSSIIIIGGGGNNNNAAAALLLLSSSS or ____BBBBSSSSDDDD____CCCCOOOOMMMMPPPPAAAATTTT before including <_s_e_t_j_m_p._h>, or
  37.  
  38.      2) specify one of them in the compile command or makefile:
  39.  
  40.           cc -D_BSD_SIGNALS -o prog prog.c
  41.  
  42.  
  43. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  44.      These functions are useful for dealing with errors and interrupts
  45.      encountered in a low-level subroutine of a program.
  46.  
  47.      All varieties of _s_e_t_j_m_p save their stack environment in _e_n_v (whose type,
  48.      _j_m_p__b_u_f, is defined in the <_s_e_t_j_m_p._h> header file) for later use by all
  49.      varieties of _l_o_n_g_j_m_p.  If the return is from a direct invocation, all
  50.      _s_e_t_j_m_ps return the value 0. If the return is from a call to any of the
  51.      _l_o_n_g_j_m_ps, all _s_e_t_j_m_p routines return a nonzero value.
  52.  
  53.      All _l_o_n_g_j_m_ps restore the environment saved by the last call of _s_e_t_j_m_p
  54.      with the corresponding _e_n_v argument.  After the _l_o_n_g_j_m_p is completed,
  55.      program execution continues as if the corresponding call of _s_e_t_j_m_p (which
  56.      must not itself have returned in the interim) had just returned the value
  57.      _v_a_l.  _l_o_n_g_j_m_ps cannot cause _s_e_t_j_m_ps to return the value 0.  If a _l_o_n_g_j_m_p
  58.      is invoked with a second argument of 0, all versions of _s_e_t_j_m_p will
  59.      return 1.  At the time of the second return from a _s_e_t_j_m_p, external and
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))                                                          SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
  71.  
  72.  
  73.  
  74.      static variables have values as of the time _l_o_n_g_j_m_p is called (see
  75.      example).  The values of register and automatic variables are undefined.
  76.      Register or automatic variables whose value must be relied upon must be
  77.      declared as volatile.
  78.  
  79. SSSSYYYYSSSSVVVV----PPPPOOOOSSSSIIIIXXXX----BBBBSSSSDDDD DDDDIIIIFFFFFFFFEEEERRRREEEENNNNCCCCEEEESSSS
  80.      The System V _s_e_t_j_m_p/_l_o_n_g_j_m_p perform identically to the 4.3BSD
  81.      __s_e_t_j_m_p/__l_o_n_g_j_m_p, i.e., they manipulate only the C stack and registers.
  82.      The 4.3BSD _s_e_t_j_m_p/_l_o_n_g_j_m_p also manipulate the C stack and registers, but
  83.      additionally save and restore the process's signal mask (see
  84.      _s_i_g_p_r_o_c_m_a_s_k(2), _s_i_g_b_l_o_c_k(3B), or _s_i_g_s_e_t_m_a_s_k(3B)).  The POSIX
  85.      _s_i_g_s_e_t_j_m_p/_s_i_g_l_o_n_g_j_m_p calls may act in either manner:  the C stack and
  86.      registers are always saved and restored, but if the _s_a_v_e_m_a_s_k parameter to
  87.      _s_i_g_s_e_t_j_m_p is non-zero, the signal mask is saved, and a bit in _e_n_v is set
  88.      to indicate that it was saved.  _s_i_g_l_o_n_g_j_m_p checks that bit to determine
  89.      if it should restore the mask or not.
  90.  
  91.      Note that the System V _l_o_n_g_j_m_p and POSIX _s_i_g_l_o_n_g_j_m_p return _v_o_i_d, whereas
  92.      the 4.3BSD _l_o_n_g_j_m_p and __l_o_n_g_j_m_p return an integer.
  93.  
  94. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  95.      #include <setjmp.h>
  96.      jmp_buf env;
  97.      int i = 0;
  98.      main ()
  99.      {
  100.          if (setjmp(env) != 0) {
  101.           (void) printf("2nd return from setjmp: i = %d\n", i);
  102.           exit(0);
  103.          }
  104.          (void) printf("1st return from setjmp: i = %d\n", i);
  105.          i = 1;
  106.          g();
  107.          /*NOTREACHED*/
  108.      }
  109.  
  110.      g()
  111.      {
  112.          longjmp(env, 1);
  113.          /*NOTREACHED*/
  114.      }
  115.  
  116.  
  117.      The program's output is:
  118.  
  119.           1st return from setjmp: i = 0
  120.           2nd return from setjmp: i = 1
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.                                                                         PPPPaaaaggggeeee 2222
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))                                                          SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
  135.  
  136.  
  137.  
  138. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  139.      sigaction(2), sigprocmask(2), signal(2), sigblock(3B), sigsetmask(3B),
  140.      sigvec(3B), signal(3B).
  141.  
  142. WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
  143.      If _l_o_n_g_j_m_p is called even though _e_n_v was never primed by a call to
  144.      _s_e_t_j_m_p, or when the last such call was in a function which has since
  145.      returned, absolute chaos is guaranteed.
  146.  
  147.      In multithreaded processes, if _l_o_n_g_j_m_p is called with an _e_n_v initialized
  148.      in different thread, the result is also guaranteed to produce chaos.
  149.      Also note that the signal mask manipulated by these interfaces is per
  150.      thread.
  151.  
  152.      If different versions of these jmp routines are mixed, unpredictable
  153.      signal masking may occur.
  154.  
  155. BBBBUUUUGGGGSSSS
  156.      The values of the registers on the second return from the _s_e_t_j_m_p_s are the
  157.      register values at the time of the first call to _s_e_t_j_m_p, not those at the
  158.      time of the _l_o_n_g_j_m_p.  This means that variables in a given function may
  159.      behave differently in the presence of _s_e_t_j_m_p, depending on whether they
  160.      are register or stack variables.
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.                                                                         PPPPaaaaggggeeee 3333
  194.  
  195.  
  196.  
  197.